<template class="container22">
  <page>
    <page-header class="wrap-head" :title="title">
    	<span @click="goOut" class="header-slot-left" slot='left'>
				<div class="left-arrow"></div>返回
			</span>
    </page-header>
		<page-content class="load-page">
			<form ref="pageForm" style="display: none;" target="pageIframe" action="https://ct.ctrip.com/m/SingleSignOn/H5SignInfo" method="post">
        <input type="hidden" name="accessuserid" value="obk_yonghui" />
        <input ref="employeeid" type="hidden" name="employeeid" value="" />
        <input ref="costCenter1" type="hidden" name="costCenter1" value="" />
        <input ref="costCenter2" type="hidden" name="costCenter2" value="" />
        <input ref="costCenter3" type="hidden" name="costCenter3" value="" />
        <input ref="signature" type="hidden" name="signature" value="" />
        <input type="hidden" name="initpage" value="Home" />
        <input type="hidden" name="appid" value="125891" />
        <input type="hidden" name="endorsementID" value="1234567" />
        <input ref="token" type="hidden" name="token" value="" />
        <input type="hidden" name="onerror" value="errorcode" />
        <input ref="submitBtn" class="goBooking" value="去订票" type="submit" @click="openIframe()" />
	    </form>
      <iframe id="pageIframe" name="pageIframe" class="iframe" ></iframe>
    </page-content>
  </page>
</template>
<style lang="less">
.solo-page-content{
	padding-bottom: 0!important;
}
.load-page{
	.iframe{
			height: 100%;
			width: 100%;
			border: none;
		}
}
</style>
<script>
  import Solo from 'solojs';
  import md5 from 'md5';

  export default {
    extends: Solo.Page,
    components: { 
    },
    data:function() { 
      return {
      	title: '携程商旅',
      }
    },
		created(){
//			this.devuserinit();
			this.kkuserinit();
    },
    methods: {
    	devuserinit(){
      		sessionStorage.setItem("userinfo",JSON.stringify({loginName:"80740945"}));
					this.init("80555760");
    	},
    	kkuserinit(){
    		var appConfig = kk.app.getAppInfo();
    		this.title = appConfig.name;
    		sessionStorage.setItem("userinfo",JSON.stringify(kk.app&&kk.app.getUserInfo()));
    		this.init(kk.app.getUserInfo().loginName);
    	},
    	init(userId){
    		//const userId = JSON.parse(sessionStorage.getItem("userinfo")).loginName;
				//const sign = md5("obk_yonghui"+userId+"public"+md5("obk_yonghui"));
				//获取ticket
				Promise.all([
					new Promise((resolve, reject)=>{
						this.http.post("/fk/mobile/fkMobileBase.do?method=getticket",{
							data:{ 's_fromApp': 'kk' }
						},(redata)=>{
							if(redata.data){
								this.$refs.token.value = redata.data[0].Token;
								this.$refs.employeeid.value = userId;
								//this.$refs.signature.value = sign;
								resolve();
							}
						})
					}),
					new Promise((resolve, reject)=>{
						this.http.fdpost("/fk/mobile/fkMobileTravel.do?method=initTravel",{
							data: {
								s_fromApp:'kk',
								fdType:'1',	//出差费报销			
								docCreatorId:userId,
							},
						},(params)=>{
							const item = params.data[0];
							this.$refs.costCenter1.value = "本部门承担";
							this.$refs.costCenter2.value = item.fdCostName+":"+item.fdCompanyName+":"+item.fdCostCode+":"+item.fdCompanyCode;
							const sign = md5("obk_yonghui"+userId+"public"+this.$refs.costCenter1.value+this.$refs.costCenter2.value+this.$refs.costCenter3.value+md5("obk_yonghui"));
							this.$refs.signature.value = sign;
							resolve();
						})
					}),
				]).then(()=>{
					this.$refs.submitBtn.click();
				})
				
				
				
				
				
				
				
    	},
    	openIframe(){
				var iframe = document.getElementById("pageIframe"); 
				this.$vux.loading.show({ text: '请求中...' });
				iframe.onload = ()=>{ 
					this.$vux.loading.hide();
				}; 
			},
    	goOut(){
    		kk.app.exit();
    	},
    }
  }
</script>


